package cn.enited.devtools.apiaggregator.entity;

import cn.enited.devtools.apiaggregator.anno.QueryField;
import cn.enited.devtools.apiaggregator.dto.ProjectDto;
import cn.enited.devtools.apiaggregator.repo.group.FindListGroup;
import cn.enited.devtools.apiaggregator.repo.group.FindOneGroup;
import cn.enited.devtools.apiaggregator.repo.group.FindPageGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Accessors(chain = true)
@Document("project")
public class Project extends BaseEntity {
    private static final long serialVersionUID = 8202906411467528041L;

    @QueryField(groups = {FindOneGroup.class, FindListGroup.class, FindPageGroup.class})
    private String name;

    @QueryField(groups = {FindOneGroup.class, FindListGroup.class, FindPageGroup.class})
    private String description;

    @QueryField(groups = {FindOneGroup.class})
    private Configuration productConfiguration;

    @QueryField(groups = {FindOneGroup.class})
    private Configuration testConfiguration;

    @QueryField(groups = {FindOneGroup.class})
    private Configuration trainingConfiguration;

    @QueryField(groups = {FindOneGroup.class})
    private Set<GlobalParameter> headParameters;

    @QueryField(groups = {FindOneGroup.class})
    private Set<GlobalParameter> bodyParameters;

    @Data
    public static class Configuration implements Serializable {
        private static final long serialVersionUID = 7378334204087718317L;

        private String defaultPathPrefix;

        private Map<String, String> specificPathPrefix;
    }

    @Data
    public static class GlobalParameter implements Serializable {
        private static final long serialVersionUID = 6293402450360416744L;

        private String name;

        private String type;

        private String value;

        private String remark;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            GlobalParameter that = (GlobalParameter) o;
            return Objects.equals(name, that.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name);
        }
    }
}
